﻿using UnityEngine;
using System.Collections;

public abstract class Toucher : MonoBehaviour 
{
    public Rect touchRect;

    Rect rect;

    protected virtual void Start()
    {
        rect = new Rect(touchRect.x * Screen.width, touchRect.y * Screen.height,
            touchRect.width * Screen.width, touchRect.height * Screen.height);
    }

    protected virtual void Update()
    {
        foreach (Touch touch in Input.touches)
        {
            if (rect.Contains(touch.position))
            {
                OnTouch();
                return;
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (rect.Contains(Input.mousePosition))
            {
                OnTouch();
                return;
            }
        }
    }

    protected abstract void OnTouch();
}
